#!/usr/bin/env python3.7.9
'''
Copyright © 2021 DUE TUL
@ date  : Monday january 11, 2020
@ desc  : This modules is used to generate sound wave graphics
@ author: Bohao,Chu 
'''
import wave
import pylab as pl
import numpy as np


f = wave.open(r"1.wav", "rb")   # open a wave file and return a Object
params = f.getparams()   # get the information of a wave file
nchannels, sampwidth, framerate, nframes = params[:4]
str_data = f.readframes(nframes)   # read a wave file to byte stream
f.close()

wave_data = np.fromstring(str_data, dtype=np.short)   #transform the byte stream to array
time = np.arange(0, nframes) * (1.0 / framerate)

pl.plot(time, wave_data)
pl.xlabel("time")
pl.ylabel("Amplitude")
pl.show()